package com.loubobooo.personal.blog.service.impl;

import com.loubobooo.personal.blog.entity.Page;
import com.loubobooo.personal.blog.entity.vo.PageVO;
import com.loubobooo.personal.blog.mapper.PageMapper;
import com.loubobooo.personal.blog.mapper.custom.PageMapperCustom;
import com.loubobooo.personal.blog.service.PageService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service public class PageServiceImpl implements PageService {
    @Autowired private PageMapperCustom pageMapperCustom;

    @Autowired private PageMapper pageMapper;

    @Override public PageVO getPageByKey(Integer status, String key)  {
        return pageMapperCustom.getPageByKey(status, key);
    }

    @Override public PageVO getPageById(Integer id)  {
        Page page = pageMapper.selectByPrimaryKey(id);
        PageVO pageVO = new PageVO();
        BeanUtils.copyProperties(page, pageVO);
        return pageVO;
    }

    @Override public List<PageVO> listPage(Integer status) {
        return pageMapperCustom.listPage(status);
    }

    @Override public void insertPage(Page page) {
        pageMapper.insert(page);
    }

    @Override public void deletePage(Integer id) {
        pageMapper.deleteByPrimaryKey(id);
    }

    @Override public void updatePage(Page page) {
        pageMapper.updateByPrimaryKeySelective(page);
    }
}
